Imports cmplib01
Imports System.Windows.Forms

Public Class frmResourceVictoryCondition
    Inherits System.Windows.Forms.Form

    Const c_Module As String = "frmResourceVictoryCondition"

    Private ptrResourceVC As ResourceVictoryCondition
    Private ptrGameData As CampaignerGameData
    Friend WithEvents btnCancel As System.Windows.Forms.Button

    Private m_Cancelled As Boolean = False

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents pnlObjectiveProperties As System.Windows.Forms.Panel
    Friend WithEvents lblDescription As System.Windows.Forms.Label
    Friend WithEvents lblAutomaticVictory As System.Windows.Forms.Label
    Friend WithEvents lblVictoryPointValue As System.Windows.Forms.Label
    Friend WithEvents lblAreaObjective As System.Windows.Forms.Label
    Friend WithEvents lblVictoryConditionName As System.Windows.Forms.Label
    Friend WithEvents txtDescription As System.Windows.Forms.TextBox
    Friend WithEvents chkAutomaticVictory As System.Windows.Forms.CheckBox
    Friend WithEvents numVPValue As System.Windows.Forms.NumericUpDown
    Friend WithEvents txtName As System.Windows.Forms.TextBox
    Friend WithEvents cboResourceType As System.Windows.Forms.ComboBox
    Friend WithEvents lblResourceAmount As System.Windows.Forms.Label
    Friend WithEvents numResourceAmount As System.Windows.Forms.NumericUpDown
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmResourceVictoryCondition))
        Me.btnOK = New System.Windows.Forms.Button
        Me.pnlObjectiveProperties = New System.Windows.Forms.Panel
        Me.numResourceAmount = New System.Windows.Forms.NumericUpDown
        Me.lblResourceAmount = New System.Windows.Forms.Label
        Me.lblDescription = New System.Windows.Forms.Label
        Me.lblAutomaticVictory = New System.Windows.Forms.Label
        Me.lblVictoryPointValue = New System.Windows.Forms.Label
        Me.lblAreaObjective = New System.Windows.Forms.Label
        Me.lblVictoryConditionName = New System.Windows.Forms.Label
        Me.txtDescription = New System.Windows.Forms.TextBox
        Me.chkAutomaticVictory = New System.Windows.Forms.CheckBox
        Me.numVPValue = New System.Windows.Forms.NumericUpDown
        Me.cboResourceType = New System.Windows.Forms.ComboBox
        Me.txtName = New System.Windows.Forms.TextBox
        Me.btnCancel = New System.Windows.Forms.Button
        Me.pnlObjectiveProperties.SuspendLayout()
        CType(Me.numResourceAmount, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.numVPValue, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnOK
        '
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(156, 286)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 3
        Me.btnOK.Text = "OK"
        '
        'pnlObjectiveProperties
        '
        Me.pnlObjectiveProperties.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlObjectiveProperties.Controls.Add(Me.numResourceAmount)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblResourceAmount)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblDescription)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblAutomaticVictory)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblVictoryPointValue)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblAreaObjective)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblVictoryConditionName)
        Me.pnlObjectiveProperties.Controls.Add(Me.txtDescription)
        Me.pnlObjectiveProperties.Controls.Add(Me.chkAutomaticVictory)
        Me.pnlObjectiveProperties.Controls.Add(Me.numVPValue)
        Me.pnlObjectiveProperties.Controls.Add(Me.cboResourceType)
        Me.pnlObjectiveProperties.Controls.Add(Me.txtName)
        Me.pnlObjectiveProperties.Location = New System.Drawing.Point(8, 8)
        Me.pnlObjectiveProperties.Name = "pnlObjectiveProperties"
        Me.pnlObjectiveProperties.Size = New System.Drawing.Size(304, 272)
        Me.pnlObjectiveProperties.TabIndex = 2
        '
        'numResourceAmount
        '
        Me.numResourceAmount.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.numResourceAmount.Increment = New Decimal(New Integer() {5, 0, 0, 0})
        Me.numResourceAmount.Location = New System.Drawing.Point(160, 88)
        Me.numResourceAmount.Maximum = New Decimal(New Integer() {10000, 0, 0, 0})
        Me.numResourceAmount.Minimum = New Decimal(New Integer() {5, 0, 0, 0})
        Me.numResourceAmount.Name = "numResourceAmount"
        Me.numResourceAmount.Size = New System.Drawing.Size(128, 20)
        Me.numResourceAmount.TabIndex = 11
        Me.numResourceAmount.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.numResourceAmount.ThousandsSeparator = True
        Me.numResourceAmount.Value = New Decimal(New Integer() {500, 0, 0, 0})
        '
        'lblResourceAmount
        '
        Me.lblResourceAmount.Location = New System.Drawing.Point(160, 64)
        Me.lblResourceAmount.Name = "lblResourceAmount"
        Me.lblResourceAmount.Size = New System.Drawing.Size(128, 16)
        Me.lblResourceAmount.TabIndex = 10
        Me.lblResourceAmount.Text = "Amount Required"
        '
        'lblDescription
        '
        Me.lblDescription.Location = New System.Drawing.Point(8, 176)
        Me.lblDescription.Name = "lblDescription"
        Me.lblDescription.Size = New System.Drawing.Size(184, 16)
        Me.lblDescription.TabIndex = 9
        Me.lblDescription.Text = "Victory Condition Description"
        '
        'lblAutomaticVictory
        '
        Me.lblAutomaticVictory.Location = New System.Drawing.Point(160, 120)
        Me.lblAutomaticVictory.Name = "lblAutomaticVictory"
        Me.lblAutomaticVictory.Size = New System.Drawing.Size(128, 16)
        Me.lblAutomaticVictory.TabIndex = 8
        Me.lblAutomaticVictory.Text = "Automatic Victory"
        '
        'lblVictoryPointValue
        '
        Me.lblVictoryPointValue.Location = New System.Drawing.Point(8, 120)
        Me.lblVictoryPointValue.Name = "lblVictoryPointValue"
        Me.lblVictoryPointValue.Size = New System.Drawing.Size(128, 16)
        Me.lblVictoryPointValue.TabIndex = 7
        Me.lblVictoryPointValue.Text = "Victory Point Value"
        '
        'lblAreaObjective
        '
        Me.lblAreaObjective.Location = New System.Drawing.Point(8, 64)
        Me.lblAreaObjective.Name = "lblAreaObjective"
        Me.lblAreaObjective.Size = New System.Drawing.Size(112, 16)
        Me.lblAreaObjective.TabIndex = 6
        Me.lblAreaObjective.Text = "Resource Type"
        '
        'lblVictoryConditionName
        '
        Me.lblVictoryConditionName.Location = New System.Drawing.Point(8, 8)
        Me.lblVictoryConditionName.Name = "lblVictoryConditionName"
        Me.lblVictoryConditionName.Size = New System.Drawing.Size(128, 16)
        Me.lblVictoryConditionName.TabIndex = 5
        Me.lblVictoryConditionName.Text = "Victory Condition Name"
        '
        'txtDescription
        '
        Me.txtDescription.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtDescription.Location = New System.Drawing.Point(11, 200)
        Me.txtDescription.Multiline = True
        Me.txtDescription.Name = "txtDescription"
        Me.txtDescription.Size = New System.Drawing.Size(280, 56)
        Me.txtDescription.TabIndex = 4
        Me.txtDescription.Text = "No Victory Condition Description"
        '
        'chkAutomaticVictory
        '
        Me.chkAutomaticVictory.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.chkAutomaticVictory.Location = New System.Drawing.Point(160, 144)
        Me.chkAutomaticVictory.Name = "chkAutomaticVictory"
        Me.chkAutomaticVictory.Size = New System.Drawing.Size(120, 24)
        Me.chkAutomaticVictory.TabIndex = 3
        Me.chkAutomaticVictory.Text = "Automatic Victory"
        '
        'numVPValue
        '
        Me.numVPValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.numVPValue.Increment = New Decimal(New Integer() {5, 0, 0, 0})
        Me.numVPValue.Location = New System.Drawing.Point(8, 144)
        Me.numVPValue.Minimum = New Decimal(New Integer() {5, 0, 0, 0})
        Me.numVPValue.Name = "numVPValue"
        Me.numVPValue.Size = New System.Drawing.Size(120, 20)
        Me.numVPValue.TabIndex = 2
        Me.numVPValue.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.numVPValue.Value = New Decimal(New Integer() {5, 0, 0, 0})
        '
        'cboResourceType
        '
        Me.cboResourceType.Location = New System.Drawing.Point(8, 88)
        Me.cboResourceType.Name = "cboResourceType"
        Me.cboResourceType.Size = New System.Drawing.Size(125, 21)
        Me.cboResourceType.TabIndex = 1
        Me.cboResourceType.Text = "<select a resource>"
        '
        'txtName
        '
        Me.txtName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtName.Location = New System.Drawing.Point(8, 32)
        Me.txtName.Name = "txtName"
        Me.txtName.Size = New System.Drawing.Size(280, 20)
        Me.txtName.TabIndex = 0
        Me.txtName.Text = "No Victory Condition Name"
        '
        'btnCancel
        '
        Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCancel.Location = New System.Drawing.Point(237, 286)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(75, 23)
        Me.btnCancel.TabIndex = 4
        Me.btnCancel.Text = "Cancel"
        '
        'frmResourceVictoryCondition
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(320, 318)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.pnlObjectiveProperties)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmResourceVictoryCondition"
        Me.Text = "Victory Condition"
        Me.pnlObjectiveProperties.ResumeLayout(False)
        Me.pnlObjectiveProperties.PerformLayout()
        CType(Me.numResourceAmount, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.numVPValue, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public ReadOnly Property Cancelled() As Boolean
        Get
            Return m_Cancelled
        End Get
    End Property

    Public Sub New(ByRef RVC As ResourceVictoryCondition, ByVal GameData As CampaignerGameData)
        Me.New()

        ptrResourceVC = RVC
        ptrGameData = GameData

        PopulateResources()
        ListProperties()

    End Sub

    Private Sub PopulateResources()
        Try
            Dim resKey As String
            Dim res As ResourceType

            For Each resKey In ptrGameData.ResourceTypes_g.HT.Keys
                res = ptrGameData.ResourceTypes_g.Item(resKey)
                cboResourceType.Items.Add(res)
            Next

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub ListProperties()
        Try
            txtName.Text = ptrResourceVC.VictoryConditionName
            txtDescription.Text = ptrResourceVC.Description
            chkAutomaticVictory.Checked = ptrResourceVC.AutomaticVictory
            numVPValue.Value = ptrResourceVC.VPValue
            numResourceAmount.Value = ptrResourceVC.AmountNeeded
            If Not ptrResourceVC.TargetResourceType Is Nothing Then
                cboResourceType.SelectedItem = ptrResourceVC.TargetResourceType
            End If
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Function SaveProperties() As Boolean

        Try
            ptrResourceVC.VictoryConditionName = txtName.Text
            ptrResourceVC.Description = txtDescription.Text
            ptrResourceVC.AutomaticVictory = chkAutomaticVictory.Checked
            ptrResourceVC.AmountNeeded = numResourceAmount.Value
            ptrResourceVC.VPValue = numVPValue.Value

            If cboResourceType.SelectedItem Is Nothing Then Return False
            ptrResourceVC.TargetResourceType = cboResourceType.SelectedItem

        Catch ex As Exception
            HandleException(c_Module, ex)
            Return False
        End Try

        Return True
    End Function

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If SaveProperties() = True Then
            Me.Hide()
        Else
            MessageBox.Show("You must select a resource for this objective.", "Select Resource", MessageBoxButtons.OK)
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        m_Cancelled = True
        Me.Hide()
    End Sub
End Class
